<?php

/**
 * This page allows a user to receive more information for a specific server.
 * 
 * @author Matthias Van Eeghem <matthias@van-eeghem.com>
 * @copyright Copyright (c) 2012, Matthias Van Eeghem
 */

// We need these defines for MySQL connections
require_once('Defines.php');

// Remove all invalid servers (server that have expired) from the masterlist before we return the info to the client
require_once('InvalidServerCheck.php');

// Open a MySQL connection
$MySQLi = new mysqli(MySQL_Server, MySQL_User, MySQL_Password, MySQL_Database);

if(isset($_GET['ip']))
{
	// Get the IP from the $_GET superglobal
	$sIP = $MySQLi->real_escape_string($_GET['ip']);
	
	$preparedStatement = $MySQLi->prepare("SELECT Version, Hostname, OnlinePlayers FROM MasterList WHERE IP=?");
	// Bind the parameters
	$preparedStatement->bind_param("s", $sIP);
	// Bind the result to variables
	$preparedStatement->bind_result($sVersion, $sHostname, $iOnlinePlayers);

	// Execute the query
	if($preparedStatement->execute())
	{
		while($preparedStatement->fetch())
		{
			// Simply echo all server information, the browser knows how to process this properly
			// All servers are split by a & character, and the individual data of the servers is split by the | character
			echo $sIP . '-' . $sVersion . '-' . $sHostname . '-' . $iOnlinePlayers;
		}
	}

	// Don't forget to close the statement
	$preparedStatement->close();
}
?>